package SERVLET;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ObraServlet extends GenericObraServlet {
    		
	@Override
	protected void adicionarAutor(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.getSession().setAttribute("redirecionar", "retornarObra");
		super.adicionarAutor(request, response);
	}
	
	@Override
	protected void editar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		obraDTO.setCodigo(Long.parseLong(request.getParameter("id")));
        obraDTO = obraBO.pesquisarPorCodigo(obraDTO.getCodigo());
		super.editar(request, response);
	}
	
	@Override
    protected void redicionarPesquisar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{    	
        request.getRequestDispatcher(HomeServlet.paginas.get("obraPesquisar")).forward(request, response);
    }
    
    @Override
    protected void redicionarIncluirAlterar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{    	
        request.getRequestDispatcher(HomeServlet.paginas.get("obraIncluirAlterar")).forward(request, response);
    }
    	
    @Override
    protected void redicionarVisualizar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{    	
        request.getRequestDispatcher(HomeServlet.paginas.get("obraVisualizar")).forward(request, response);
    }
    
    @Override
    protected void redicionarPesquisarAtualizarLista(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	removerAtributo(request);
    	request.getSession().setAttribute("obras", obraBO.pesquisarTodosLivros());
    	request.getRequestDispatcher(HomeServlet.paginas.get("obraPesquisar")).forward(request, response);    	
    }
}